<!DOCTYPE html>
<html>

<head>
    <include file="public@head" title="留言管理" />
</head>

<body class="layui-layout-admin">
<include file="public@header"/>
<include file="public@side"/>
<div class="layui-body">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a href="{:url('admin/index/index')}">主页</a>
        <a>用户管理</a>
        <a href="{:url('index')}"><cite>留言管理</cite></a>
    </div>
    <div class="layui-fluid pdt10">
        <div class="layui-card">
            <div class="layui-card-body">
                <table class="layui-hide table-center" id="lists" lay-filter="lists"></table>

                <script type="text/html" id="barLists">
                    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除</a>
                </script>
            </div>
        </div>
    </div>
</div>
<include file="public@scripts"/>
<script>
    var table = layui.table;

    table.render({
        elem: '#lists',
        id: 'listsReload',
        even: true,
        url: "{:url('getContacts')}",
        cols: [[
            {field: 'id', title: '编号', align: 'center', width: 60}
            , {field: 'name', title: '姓名',width:120}
            , {field: 'mobile', title: '手机号', width: 150, align: 'center'}
            , {field: 'email', title: '邮箱', width:240 ,align: 'center'}
            , {field: 'content', title: '留言内容'}
            , {field: 'create_time', title: '留言时间',width:180, align: 'center'}
            , {field: 'remark', title: '备注',edit:'text'}
            , {title: '操作', align: 'center',width:100, toolbar: '#barLists'}
        ]],
        page: true
    });

    table.on('edit(lists)', function(obj) {
        var value = obj.value,
            data = obj.data,
            field = obj.field;
        $.ajax({
            type: "post",
            url: "{:url('updateField')}?id=" + data.id + "&field=" + field + "&value=" + value,
        });
    });
    //监听工具条
    table.on('tool(lists)', function(obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if(layEvent === 'delete') {
            layer.confirm('将删除【' + data.name + '】的留言', function(index) {
                obj.del();
                layer.close(index);
                $.ajax({
                    type: "post",
                    url: "{:url('delete')}?id=" + data.id,
                    async: true
                });
            });
        }
    });
</script>
</body>

</html>
